package model.map;

import model.core.GameScheduler;
import model.core.Notifiable;
import model.entity.Avatar;

/**
 * This class tells the game map when to be drawn
 * (by the DrawVisitor).
 * @author Zachary
 */
public class GameStateObserver implements Notifiable{
	private DrawMapVisitor drawer;
	private GameMap map;
	private int semaphore = 0;
	
	/**
	 * Constructor for the GameStateObserver.
	 * @param gameMap
	 * @param viewMap
	 * @param avatar
	 */
	public GameStateObserver(GameMap gameMap, ViewMap viewMap, Avatar avatar){
		this.drawer = new DrawMapVisitor(avatar, viewMap);
		this.map = gameMap;
		GameScheduler.getInstance().register(1, this);
	}
	
	/**
	 * This method causes the game drawing to occur.
	 */
	public void execute() {
		map.acceptMapVisitor(drawer);
		if(++semaphore == 1){
			map.flash(drawer);
		}
	}
}
 